package com.example.templateapp.util

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.fastjson.JSON
import com.xuexiang.xutil.tip.ToastUtils
import rxhttp.wrapper.exception.HttpStatusCodeException

fun AppCompatActivity.toActivity(clazz: Class<out AppCompatActivity>) {
    this.startActivity(Intent(this, clazz))
}

fun toastException(throwable: Throwable) {
    throwable.printStackTrace()
    var msg: String
    msg = try {
        val result = JSON.parseObject((throwable as HttpStatusCodeException).result)
        result.getString("message")
    } catch (e: Exception) {
        e.message.toString()
    }
    if (msg.isNotEmpty()) {
        ToastUtils.toast(msg)
    }
}
